<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <!--<div class="title-container">
            新建一个发起事项
        </div>-->
        <!--<div class="toolbar-container">
            <button class="layui-btn layui-btn-sm" id="btnLaunchProcess">
                <i class="layui-icon">&#xe608;</i> 督办事项发起
            </button>
        </div>-->
        <div>
            <div class="widget-body no-padding">
                <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                    <tr>
                    </tr>
                    <tr>
                        <th style="display: none">id</th>
                        <th>问题项</th>
                        <th>单位</th>
                        <th>问题类型</th>
                        <th>巡察年度</th>
                        <th>问题状态</th>
                        <!--<th>录入时间</th>-->
                        <th>当前处理人</th>
                        <th>督察方式</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div id="openProductBox" style="display: none; padding: 10px;">
    <table id="openProductTable" lay-filter="openProductTable"></table>
</div>
<script type="text/html" id="openProductCount">
    <a href="javascript:;" class="layui-table-link" style="display: inline-block; width: 100%;"
       onclick="openProductCount('{{d.companyId}}')">{{d.openProductCount}}</a>
</script>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript">
    /**
     * 发起督办问题行为
     */
    $('#btnLaunchProcess').click(function () {
        formOpen()
    })


    /**
     * 弹出window
     */
    function formOpen() {
        window.open('overseeQuestionPanel.html', 'toolbar =no, menubar=no')
    }


    layui.use('layer', function () {
        var layer = layui.layer;
    });
    var questionStatus = showDictSelect("questionStatus", "questionStatus", true);
    var questionKeyword = showDictSelect("questionKeyword", "questionKeyword", true);
    var questionType = showDictSelect("questionType", "questionType", true);

    console.log(questionType)
    var pers = checkPermission();

    var example;

    function init() {
        example =
            $('#dt-table').DataTable({
                "searching": false,
                "processing": false,
                "serverSide": true,
                "ordering": false,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/mOverseeQuestions/list",
                    "type": "get",
                    "data": function (d) {
                        d.question = $('#question').val();
                        d.questionKeyword = $("#questionKeyword option:selected").text();
                        d.questionType = $("#questionType option:selected").text();
                        d.questionStatus = $("#questionStatus option:selected").text();
                    },
                    "error": function (xhr, textStatus, errorThrown) {
                        var msg = xhr.responseText;
                        console.log(msg);
                        var response = JSON.parse(msg);
                        var code = response.code;
                        var message = response.message;
                        if (code == 400) {
                            layer.msg(message);
                        } else if (code == 401) {
                            localStorage.removeItem("token");
                            layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function () {
                                location.href = '/login.html';
                            });
                        } else if (code == 403) {
                            console.log("未授权:" + message);
                            layer.msg('未授权');
                        } else if (code == 500) {
                            layer.msg('系统错误：' + message);
                        }
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    /*{"data" : "id", "defaultContent" : ""},*/
                    {"data": "question", "defaultContent": ""},
                    {"data": "branch", "defaultContent": ""},
                    {"data": "questionType", "defaultContent": ""},
                    {"data": "startPatrolTime", "defaultContent": ""},
                    {"data": "questionStatus", "defaultContent": ""},
                    /*{"data" : "createTime", "defaultContent" : ""},*/
                    {"data": "oversee", "defaultContent": ""},
                    {"data": "overseeForm", "defaultContent": ""},
                    /*{
                        "data": "questionStatus",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return questionStatus[data];
                        }
                    },
                    {
                        "data": "questionType",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return questionType[data];
                        }
                    },
                    {
                        "data": "questionKeyword",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return questionKeyword[data];
                        }
                    },*/
                    {
                        "data": "",
                        "defaultContent": "",
                        "orderable": false,
                        "render": function (data, type, row) {
                            var id = row['id'];
                            var href = "updateQuestionPanel.html?id=" + id;
                            var edit = buttonOpen(href, "", pers);
                            var del = buttonDel(id, "", pers);
                            //  var record = buttonRecord(id, "", pers);
                            return edit + del;
                        }
                    },

                ],
                "order": [[0, "asc"]]
            });
    }

    function del(id) {
        layer.confirm('确定要删除吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'delete',
                url: '/mOverseeQuestions/' + id,
                success: function (data) {
                    example.ajax.reload();
                    layer.msg('删除成功');
                }
            });

            layer.close(1);
        });
    }

    var questionId = '';


    layui.use('table', function () {
        var table = layui.table;
        console.log(questionId);
        table.render({
            elem: '#test'
            , method: 'get'
            , url: '/questionRecords/' + questionId
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true}
                , {field: 'questionStatus', width: 80, title: '整改进度'}
                , {field: 'checkStatus', width: 80, title: '审核状态'}
                , {field: 'overseeForm', width: 80, title: '督察形式'}
                , {field: 'updateUser', title: '记录人员', width: '30%', minWidth: 100} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
                , {field: 'createTime', title: '记录时间', sort: true}
                , {field: 'detail', title: '详情'}
            ]]
        });
    });

    var table2;

    function record(companyId) {
        fkCompanyId = companyId;
        layui.use(['table', 'form'], function () {
            table2 = layui.table;
            var form = layui.form;
            layer.open({
                type: 1,
                title: '问题修改记录',
                area: ['80%', '90%'], //宽高
                content: $('#openProductBox'),
                end: function () {
                    vm.query.productName = '';
                },
                success: function () {
                    table2.render({
                        elem: '#openProductTable',
                        id: 'openProductTable',
                        height: 480,
                        method: 'get', //接口http请求类型，默认：get
                        url: '/questionRecords/' + companyId, //?page=1&limit=10（该参数可通过 request 自定义）
                        cols: [
                            [{
                                field: 'questionStatus', //字段名
                                title: '整改进度', //标题
                                width: 100,
                                //fixed: 'left' //固定列
                            }, {
                                field: 'checkStatus', //字段名
                                title: '审核状态', //标题
                                width: 100
                                //fixed: 'left' //固定列
                            }, {
                                field: 'updateUser', //字段名
                                title: '记录人员', //标题
                                width: 100
                                //fixed: 'left' //固定列
                            }, {
                                field: 'createTime', //字段名
                                title: '记录时间', //标题
                                sort: true,
                                width: 200
                                //fixed: 'left' //固定列
                            }, {
                                field: 'detail', //字段名
                                title: '记录详情', //标题

                                //fixed: 'left' //固定列
                            }]
                        ]
                    });
                }
            });
        });
    }

    // 发起修改
    function edit(data) {
        window.open(data, 'toolbar =no, menubar=no')

    }


    $("#searchBt").click(function () {
        example.ajax.reload();
    });

    init();


</script>
</body>
</html>


